<!DOCTYPE html>
<html lang="en"  xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- layui样式 -->
    <link rel="stylesheet" href="../../layui/css/layui.css">
    <title>Document</title>
    <style>
        .layui-tab-title {
            color: #333 !important;
        }

        .layui-tab-brief>.layui-tab-title .layui-this {
            color: #333 !important;
        }

        .layui-tab-brief>.layui-tab-more li.layui-this:after,
        .layui-tab-brief>.layui-tab-title .layui-this:after {
            border: none;
            border-radius: 0;
            border-bottom: 1px solid #000;
        }

        .avatar-add {
            position: relative;
            width: 100%;
            height: 384px;
        }

        .avatar-add p {
            position: absolute;
            top: 70px;
            width: 100%;
            margin-top: 10px;
            font-size: 12px;
            text-align: center;
            color: #999;
        }

        .avatar-add .upload-img {
            position: absolute;
            left: 50%;
            top: 35px;
            margin: 0 0 0 -56px;
        }

        .avatar-add img {
            position: absolute;
            left: 50%;
            top: 50%;
            width: 168px;
            height: 168px;
            margin: -50px 0 0 -84px;
            border-radius: 100%;
        }

        .foot {
            height: 49px !important;
            line-height: 49px;
            text-align: right;
            background-color: #f5f5f5;
            border-top: 1px #e5e5e5 solid;
        }

        .foot button {
            width: 62px;
            height: 28px;
            line-height: 28px;
            margin-left: 2px;
            margin-right: 15px;
        }
        .foot .close:hover{
            border-color: #1E9FFF;
        }
    </style>
</head>

<body style="background-color: #ffffff">
<form class="layui-form" action="">
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                        <ul class="layui-tab-title">
                            <li class="layui-this"><i class="czs-face-l"></i>设置我的资料</li>
                            <li>设置头像</li>
                        </ul>
                        <div class="layui-tab-content">
                            <div class="layui-tab-item layui-show">
                                <div class="layui-card-body" style="padding: 0;padding-top: 4px;padding-left: 4px;">
                                    <div class="layui-form" lay-filter="">
                                        <div class="layui-form-item">
                                            <label class="layui-form-label">账号</label>
                                            <div class="layui-input-inline">
                                                <!--@thymesVar id="user" type=""-->
                                                <input type="text" name="account" style="color: #999"
                                                       th:value="${user.account}" readonly="" class="layui-input">
                                            </div>
                                            <div class="layui-form-mid layui-word-aux">不可修改</div>
                                        </div>
                                        <div class="layui-form-item">
                                            <label class="layui-form-label">昵称</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="userName" th:value="${user.name}" lay-verify="nickname"
                                                       autocomplete="off" placeholder="请输入昵称" class="layui-input"
                                                >
                                            </div>
                                        </div>
                                        <div class="layui-form-item">
                                            <label class="layui-form-label">性别</label>
                                            <div class="layui-input-block">
                                                <input type="radio" name="sex" value="0" title="男">
                                                <div class="layui-unselect layui-form-radio">
                                                    <i class="layui-anim layui-icon"></i>
                                                    <div>男</div>
                                                </div>
                                                <input type="radio" name="sex" value="1" title="女">
                                                <div class="layui-unselect layui-form-radio layui-form-radioed">
                                                    <i class="layui-anim layui-icon"></i>
                                                    <div>女</div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="layui-form-item">
                                            <label class="layui-form-label">年龄</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="age" th:value="${user.age}"
                                                       class="layui-input">
                                            </div>
                                        </div>
                                        <div class="layui-form-item">
                                            <label class="layui-form-label">邮箱</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="email" value="12345678@qq.com"
                                                       placeholder="请输入邮箱" class="layui-input">
                                            </div>
                                        </div>
                                        <div class="layui-form-item layui-form-text">
                                            <label class="layui-form-label">简介</label>
                                            <div class="layui-input-block">
                                                    <textarea name="comment" placeholder="请输入备注"
                                                              class="layui-textarea" th:text="${user.comment}"></textarea>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-tab-item">
                                <div class="avatar-add">
                                    <p>建议尺寸168*168，支持jpg、png、gif，最大不能超过50KB</p>
                                    <button type="button" class="layui-btn layui-btn-normal upload-img" id="test1">
                                        <i class="layui-icon">&#xe67c;</i>上传图片
                                    </button>
                                    <img class="img1" th:src="${user.photo}">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="foot">
        <button type="button" class="layui-btn layui-btn-normal layui-btn-sm"  lay-submit="" lay-filter="setmyinfo">确定</button>
    </div>
</form>



    <!-- layui JS -->
    <script src="/layui/layui.js"></script>
<script src="/js/jquery.js"></script>
<script src="/js/common.js"></script>
    <script>
        layui.use(['form', 'jquery', 'layer', 'element', 'upload'], function () {
            var form = layui.form;
            var $ = layui.jquery;
            var layer = layui.layer;
            var element = layui.element;
            var upload = layui.upload;
            var id=[[${user.id}]];
            //执行实例
            var uploadInst = upload.render({
                elem: '#test1' //绑定元素
                , url: '/visiter/upload/'+id//上传接口
                ,before: function(obj){

                    obj.preview(function(index, file, result){

                        $('#test1').attr('src', result);
                    });
                }
                , done: function (res) {
                    //上传完毕回调
                    if(res.code===0){
                        layer.msg('上传成功');
                        var fileupload = $(".img1");
                        // http://localhost:8080/images/2021-05-16/2b3e36e7-41c2-4a69-98ea-7346389f995b.png
                        // http://localhost:8080/images/2021-05-16/6ea2f585-8ed6-43b2-8337-ecb4630ad3ae.png
                        fileupload.attr("src",res.data);
                    }
                }
                , error: function () {
                    //请求异常回调
                }
            });

            //监听提交
            form.on('submit(setmyinfo)', function (data) {
                // parent.layer.alert(JSON.stringify(data.field));
                // var index = parent.layer.getFrameIndex(window.name);
                // parent.layer.close(index);
                // return false;

                $.ajax({
                    url: '/visiter/update',
                    type: "get",
                    dataType: 'json',
                    data: {
                        'data': JSON.stringify(data.field)
                    },
                    success: function (data) {
                        if (data['code'] == 0) {
                            parent.layer.msg("修改成功", { icon: 1 });
                        } else {
                            parent.layer.msg("修改失败", { icon: 2 });
                        }
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭  
                    }
                })

                return false;
            });


            $('.close').click(function(){
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭  
                return false;
            })

        });

    </script>
<script>
    $(function(){
        var sex=[[${user.sex}]];
        console.log(1);
        var Obj = document.getElementsByName('sex');
        for(var i = 0;i < Obj.length;i++){
            if(Obj[i].value == sex){
                Obj[i].checked =  'checked';
            }
        }
    });
</script>

</body>

</html>